<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>跳跃游戏II</title>
</head>
<body>
  <script>
    function fn(nums) {
      let a = 0, b = 0, c = 0;
      for (let i = 0; i < nums.length - 1; i++) {
        b = Math.max(nums[i] + i, b)
        if (i === a) {
          a = b
          c++
        }
      }
      return c
    }
    console.log(fn([2, 3, 1, 1, 4]))
  </script>
</body>
</html>